package com.mjh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mjh.pojo.WChxhRzqgzyjdjDt3;
import com.mjh.service.IWChxhRzqgzyjdjDt3Service;
import com.mjh.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;

/**
 *
 * 任职前工作业绩登记 前端控制器
 *
 *
 * @author MJH
 * @since 2021-12-03
 */
@RestController
@RequestMapping("/offront")
public class WChxhRzqgzyjdjDt3Controller {

    @Autowired
    private HttpServletRequest request;
    @Autowired
    private IWChxhRzqgzyjdjDt3Service iwChxhRzqgzyjdjDt3Service;
    /**
     * 任职前工作业绩添加
     * @param dt3
     */
    @PostMapping("/offrontadd")
    public  void offrontadd(@RequestBody WChxhRzqgzyjdjDt3 dt3){
        Integer userId = (Integer) JwtUtil.getPayload(request, "userId");
        dt3.setCreateUserId(userId);
        iwChxhRzqgzyjdjDt3Service.save(dt3);
    }

    /**
     * 任职前工作业绩批量或单一删除
     * @param offrontid
     */
    @PostMapping("/offrontdle")
    public void offrontdle(@RequestBody Integer [] offrontid){
        iwChxhRzqgzyjdjDt3Service.removeByIds(Arrays.asList(offrontid));
    }

    /**
     * 任职前工作业绩分页查询
     * @param currentPage 当前页码
     * @param pageSize  每页数量
     * @return
     */
    @GetMapping("/offrontslt")
    public ResponseEntity<Object> offrontslt(@RequestParam(defaultValue = "1") Integer currentPage,
                                             @RequestParam(defaultValue = "10")  Integer pageSize){
        Page<WChxhRzqgzyjdjDt3> page = new Page<>(currentPage,pageSize);
        Integer userId = (Integer)JwtUtil.getPayload(request, "userId");
        Page<WChxhRzqgzyjdjDt3> wtzxPage =iwChxhRzqgzyjdjDt3Service.offrontslt(page,userId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",wtzxPage.getTotal());
        map.put("currentPage",wtzxPage.getCurrent());
        map.put("list",wtzxPage.getRecords());
        return ResponseEntity.ok(map);
    }
}
